package Tools;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import play.Play;

public class FileHepler {
    
    public static String pathSep = File.separator;
    
	public static File createNewFile(String filePath){
		SimpleDateFormat sfd = new SimpleDateFormat("yyyyMMddHHmmss");
		File ArticleImgPath = new File(Play.applicationPath + pathSep + filePath);
		if(!ArticleImgPath.exists()){
			ArticleImgPath.mkdirs();
		}
		File ArticleImg = new File(ArticleImgPath,sfd.format(new Date()) + ".jpg");
		try {
			ArticleImg.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ArticleImg;
	}
	
	/**
	 * 根据文件路径返回文件
	 * 
	 * @throws FileNotFoundException **/
	public static File getFile(String filePath) throws FileNotFoundException{
	    File file = new File(Play.applicationPath + pathSep + filePath);
	    if(!file.exists()) throw new FileNotFoundException();
	    return file;
	}
}
